package com.fang.networkdisk.controller;

import com.fang.common.common.CommonPage;
import com.fang.common.common.CommonResult;
import com.fang.common.request.BaseController;
import com.fang.common.util.CommonResultUtil;
import com.fang.networkdisk.entity.bo.RolePermitRelationBo;
import com.fang.networkdisk.entity.dto.RolePermitRelationDto;
import com.fang.networkdisk.entity.vo.RolePermitRelationVo;
import com.fang.networkdisk.service.TbNetDisRolePermitRelationService;
import com.fang.networkdisk.util.NDBeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description
 * @Author Bernie_fang
 * @Date 2025/3/1 16:33
 **/
@RestController
@RequestMapping("/system/rolePermitRelation")
public class RolePermitRelationController extends BaseController {

    @Resource
    private TbNetDisRolePermitRelationService rolePermitRelationService;

    @PostMapping("/list")
    public CommonResult<CommonPage<List<RolePermitRelationVo>>> queryRolePermitRelation(@RequestBody RolePermitRelationDto rolePermitRelationDto) {
        RolePermitRelationBo rolePermitRelationBo = new RolePermitRelationBo();
        NDBeanUtils.copyListProperties(rolePermitRelationDto, rolePermitRelationBo);
        CommonPage result = rolePermitRelationService.queryRolePermitRelation(rolePermitRelationBo);
        return CommonResultUtil.success(result);
    }

    @PostMapping("/add")
    public CommonResult<CommonPage<List<RolePermitRelationVo>>> addRolePermitRelation(@RequestBody RolePermitRelationDto rolePermitRelationDto) {
        String authorId = super.getAuthorId();
        RolePermitRelationBo rolePermitRelationBo = new RolePermitRelationBo();
        NDBeanUtils.copyListProperties(rolePermitRelationDto, rolePermitRelationBo);
        rolePermitRelationBo.setCreateUser(authorId);
        rolePermitRelationBo.setUpdateUser(authorId);
        rolePermitRelationService.addRolePermitRelation(rolePermitRelationBo);
        return CommonResultUtil.success();
    }

    @PostMapping("/update")
    public CommonResult<CommonPage<List<RolePermitRelationVo>>> updateRolePermitRelation(@RequestBody RolePermitRelationDto rolePermitRelationDto) {
        String authorId = super.getAuthorId();
        RolePermitRelationBo rolePermitRelationBo = new RolePermitRelationBo();
        NDBeanUtils.copyListProperties(rolePermitRelationDto, rolePermitRelationBo);
        rolePermitRelationBo.setCreateUser(null);
        rolePermitRelationBo.setUpdateUser(authorId);
        rolePermitRelationService.updateRolePermitRelationById(rolePermitRelationBo);
        return CommonResultUtil.success();
    }

    @GetMapping("/delete/{id}")
    public CommonResult<CommonPage<List<RolePermitRelationVo>>> deleteRolePermitRelation(@PathVariable("id") Integer id) {
        String authorId = super.getAuthorId();
        rolePermitRelationService.deleteRolePermitRelationById(id, authorId);
        return CommonResultUtil.success();
    }
}
